package cn.webestar.scms.user.api.dto.Employee;

import cn.webestar.scms.commons.api.PageBody;
import cn.webestar.scms.user.entity.Employee;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "EmployeePageDTO")
public class EmployeePageDTO extends PageBody {

    @Schema(description = "租户ID")
    private Long cid;

    @Schema(description = "用户id")
    private Long userId;

    @Schema(description = "部门id")
    private Long depId;

    @Schema(description = "员工号")
    private String no;

    @Schema(description = "姓名")
    private String name;

    @Schema(description = "邮箱")
    private String email;

    @Schema(description = "创建人")
    private Long creator;

    @Schema(description = "更新人")
    private Long updater;

    @Schema(description = "删除人")
    private Long deleter;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Schema(description = "删除时间")
    private Date deleteTime;

    @Schema(description = "是否已删除")
    private Boolean isDeleted;

    @Override
    public LambdaQueryWrapper<Employee> toQueryWapper() {
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
        if (cid!=null) {
            queryWrapper.eq(Employee::getCid, cid);
        }
        if (userId!=null) {
            queryWrapper.eq(Employee::getUserId, userId);
        }
        if (depId!=null) {
            queryWrapper.eq(Employee::getDepId, depId);
        }
        if (StringUtils.hasText(no)) {
            queryWrapper.eq(Employee::getNo, no);
        }
        if (StringUtils.hasText(name)) {
            queryWrapper.eq(Employee::getName, name);
        }
        if (StringUtils.hasText(email)) {
            queryWrapper.eq(Employee::getEmail, email);
        }
        if (creator!=null) {
            queryWrapper.eq(Employee::getCreator, creator);
        }
        if (updater!=null) {
            queryWrapper.eq(Employee::getUpdater, updater);
        }
        if (deleter!=null) {
            queryWrapper.eq(Employee::getDeleter, deleter);
        }
        if (createTime!=null) {
            queryWrapper.eq(Employee::getCreateTime, createTime);
        }
        if (updateTime!=null) {
            queryWrapper.eq(Employee::getUpdateTime, updateTime);
        }
        if (deleteTime!=null) {
            queryWrapper.eq(Employee::getDeleteTime, deleteTime);
        }
        if (isDeleted!=null) {
            queryWrapper.eq(Employee::getIsDeleted, isDeleted);
        }
        return queryWrapper;
    }

}
